package Method_References;

import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class number3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一串字符串：");
        String inputstr = sc.next();
        System.out.println("请输入一个数字：");
        int num = sc.nextInt();
        
        char[] arraystr = inputstr.toCharArray();
        
        IntStream.range(0, arraystr.length)
                 .mapToObj(i -> arraystr[i]) // 将字符数组转换为IntStream
                 .collect(Collectors.groupingBy(c -> c, Collectors.counting())) // 统计每个字符出现的次数
                 .entrySet().stream()
                 .filter(entry -> entry.getValue() == num) // 过滤出与指定数字相同次数的字符
                 .map(entry -> entry.getKey()) // 获取字符
                 .forEach(System.out::println); // 输出结果
    }
}
